@extends('d.layout.index')
@section('con')
<div class="mws-panel grid_8">
 	<div class="mws-panel-header">
     	<span>请选择类别</span>
     </div>

     <div class="mws-panel-body no-padding">
     	@if($action == 'scan')
     	<form class="mws-form" action="/admin/goods/index" method="get">
     	@else
     	<form class="mws-form" action="/admin/goods/add" method="get">
     	@endif
               {{csrf_field()}}
     		
     		<div class="mws-form-row">
				<div class="mws-form-item">
					<select class="large" style="margin:10px">
						<option value="1000000000" selected>请选择</option>
						@foreach($list as $v)
                      	<option value="{{$v['id']}}">{{$v['name']}}</option>
                        @endforeach
					</select>
				</div>
			</div>

               
     		<div class="mws-button-row">
     			@if($action == 'scan')
     			<input type="submit" value="浏览" class="btn btn-danger">
     			@else
     			<input type="submit" value="添加" class="btn btn-danger">
     			@endif
     			<input type="reset" value="重置" class="btn ">
     		</div>
     	</form>
     </div>    	
</div>
<script type="text/javascript" src='/d/js/libs/jquery-1.8.3.js'></script>
<script type="text/javascript">

	$('select').live('change',function() {
		var index = $(this).index();
		$('select:gt('+index+')').remove();
		if($(this).value=='') {
			return;
		};
		$.ajax({
			url:'/admin/goods/type',
			data:{'pid':$(this).val(),'_token':$('input[type=hidden]').val()},
			dataType:'json',
			type:'post',
			success:function(mes) {
				if(mes.length == 0) {
					return;
				};

				var sel = $('<select class="large" name="tid'+(index+1)+'" style="margin:10px"></select>');
				sel.appendTo($('.mws-form-item'));
				$(mes).each(function() {
					var op = $('<option value="'+$(this).attr('id')+'">'+$(this).attr('name')+'</option>');
					op.appendTo(sel);
				});
					var op = $('<option value="100000000" selected>请选择</option>');
					op.appendTo(sel);
			},
		})
	})

</script>
@endsection